package cn.tedu.straw.portal.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import javafx.scene.input.TouchPoint;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<E> {
    private Integer state;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String message;
    private E data;
    public static Result ok(){
        return new Result().setState(State.OK);
    }

    public static Result fail(Integer state,String message){
        return new Result().setState(state).setMessage(message);
    }

    public static Result fail(Integer state,Throwable e){
        return new Result().setState(state).setMessage(e.getMessage());
    }

    public static <E> Result ok(E data){
        return new Result().setState(State.OK).setData(data);
    }

    public interface State {
        int OK = 2000;
        int ERR_INVITE_CODE = 4010;
        int ERR_CLASS_DISABLED = 4020;
        int ERR_PHONE_DUPLICATE = 4030;
        int ERR_INSERT = 4040;
        int ERR_PARAM_VALIDATION = 4050;
        int ERR_FILE_UPLOAD_EMPTY=4060;
        int ERR_FILE_UPLOAD_SIZE=4070;
        int ERR_FILE_UPLOAD_TYPE=4080;
        int ERR_FILE_UPLOAD_IO=4090;
        int ERR_FILE_UPLOAD_STATE=4100;
        int ERR_QUESTION_NOT_FOUND=4110;
        int ERR_ANSWER_NOT_FOUND=4120;
    }
}
